//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "tyr_fnccontainer\execHandler.sqf"
#include <core_macros.h>

TRACE_1("Start",_this);

private ["_handler","_results","_idx","_array","_index","_params","_fnc","_debug","_result"];

_handler = toupper(_this select 0);
_params = [];
if (count _this > 1) then { _params = _this select 1 };
_index = -1;
if (count _this > 2) then { _index = _this select 2 };
_results = [];

_handlers_list = TYR_FUNCTIONS_HANDLER_LIST select 0;
_functions_list = TYR_FUNCTIONS_HANDLER_LIST select 1;

_idx = _handlers_list find _handler;
if (_idx >= 0) then {
	if (_idx < count _functions_list) then {
		_array = _functions_list select _idx;
		if (typename _array == typename []) then {
			if (count _array > 0) then {
				if (_index >= 0) then {
					if (_index >= count _array) then { _index = ((count _array) - 1) };
					TRACE_1("one",ARR_2(_index,(count _array)));
					_fnc = _array select _index;
					if (!isnil "_fnc") then {
						_result = [];
						if (typename _fnc == typename []) then {
							_result = _fnc;
						} else {
							if (typename _fnc == typename "") then {
								_result = call compile preprocessfilelinenumbers format[_fnc,_params];
							} else {
								_result = _params call _fnc;
							};
						};
						if (isnil "_result") then { _result = [] };
						TRACE_1("_result",_result);
						{ _results set [count _results, _x];
						} foreach _result;
					};
				} else {
					TRACE_1("all",ARR_2(_index,(count _array)));
					{
						_fnc = _x;
						if (!isnil "_fnc") then {
							_result = [];
							if (typename _fnc == typename []) then {
								_result = _fnc;
							} else {
								if (typename _fnc == typename "") then {
									_result = call compile preprocessfilelinenumbers format[_fnc,_params];
								} else {
									_result = _params call _fnc;
								};
							};
							if (isnil "_result") then { _result = [] };
							TRACE_1("_result",_result);
							{ _results set [count _results, _x];
							} foreach _result;
						};
					} foreach _array;
				};
			};
		};
	};
};
TRACE_1("End",count _results);
_results;